package com.ems.controller;

import com.ems.config.LogPointer;
import com.ems.service.IAreaService;
import com.ems.util.SnowflakeIdWorker;
import com.ems.vo.AreaVo;
import com.ems.vo.BaseResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 省市县区 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2023-06-23
 */
@RestController
@RequestMapping ( "/area" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class AreaController {

    @Resource
    private IAreaService iAreaService;

    @RequestMapping ( "queryList" )
    @LogPointer ("城市区域列表")
    public BaseResult queryList ( @RequestBody AreaVo areaVo ) {
        List<AreaVo> areaEntities = iAreaService.queryList ( areaVo );
        return BaseResult.success ( areaEntities );
    }

    @RequestMapping ( "saveSingle" )
    @LogPointer("保存城市区域")
    public BaseResult saveSingle ( @RequestBody AreaVo areaVo ) {
        areaVo.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        areaVo = iAreaService.saveSingle ( areaVo );
        return BaseResult.success ( areaVo );
    }

}
